#include "pcaPage.h"
#include <iostream>

PCAPage::PCAPage(std::vector<QString> _names, QWidget *_parent) : QWidget(_parent){
    image = 0;
    type = 0;
    lambda = 0;
    multipleImages = true;
    if(_names.size() == 1) multipleImages = false;



    QVBoxLayout *mainLayout = new QVBoxLayout;

    if(multipleImages) {
        QLabel *imageLabel = new QLabel(tr("Vizaualizar imagem: "));
        lambdaLabel = new QLabel(QString::fromUtf8("Número de lambdas usados: "));

        QComboBox *imageComboBox = new QComboBox(this);
        lambdaComboBox = new QComboBox(this);

        QString str;
        for(unsigned int i = 0; i < _names.size(); i++){
            imageComboBox->addItem(_names.at(i));
            str.setNum(i+1);
            lambdaComboBox->addItem(str);
        }

        connect(imageComboBox, SIGNAL(activated(int)), this, SLOT(changeImage(int)));
        connect(lambdaComboBox, SIGNAL(activated(int)), this, SLOT(changeLambda(int)));

        QHBoxLayout *imageLayout = new QHBoxLayout;
        imageLayout->addWidget(imageLabel);
        imageLayout->addWidget(imageComboBox);
        imageLayout->addStretch(100);


        QHBoxLayout *lambdaLayout = new QHBoxLayout;
        lambdaLayout->addWidget(lambdaLabel);
        lambdaLayout->addWidget(lambdaComboBox);
        lambdaLayout->addStretch(100);


        mainLayout->addLayout(imageLayout);
        mainLayout->addStretch();
        mainLayout->addLayout(lambdaLayout);
        mainLayout->addStretch();

    }



    //--------------------- criando group box do afixamento
    QRadioButton *radioX = new QRadioButton(tr("Normal (x)"));
    QRadioButton *radioY = new QRadioButton(tr("Transformado (y)"));
    connect(radioX, SIGNAL(toggled(bool)), this, SLOT(changeTypeX(bool)));
    connect(radioY, SIGNAL(toggled(bool)), this, SLOT(changeTypeY(bool)));
    radioX->setChecked(true);

    QVBoxLayout *typeLayout = new QVBoxLayout;
    typeLayout->addWidget(radioX);
    typeLayout->addWidget(radioY);

    if(multipleImages) {
        QRadioButton *radioDifferenceY = new QRadioButton(QString::fromUtf8("Diferença entre normal e a transformação"));
        QRadioButton *radioReconstructed = new QRadioButton(tr("Reconstruido"));
        QRadioButton *radioDifferenceReconstructed = new QRadioButton(QString::fromUtf8("Diferença entre normal e reconstruido"));
        connect(radioDifferenceY, SIGNAL(toggled(bool)), this, SLOT(changeTypeDifferenceY(bool)));
        connect(radioReconstructed, SIGNAL(toggled(bool)), this, SLOT(changeTypeReconstructed(bool)));
        connect(radioDifferenceReconstructed, SIGNAL(toggled(bool)), this, SLOT(changeTypeDifferenceReconstructed(bool)));

        typeLayout->addWidget(radioDifferenceY);
        typeLayout->addWidget(radioReconstructed);
        typeLayout->addWidget(radioDifferenceReconstructed);
    }
    typeLayout->addStretch(1);


//    QGroupBox *typeGroupBox = new QGroupBox(tr("Nha"));
//    typeGroupBox->setLayout(typeLayout);




    mainLayout->addLayout(typeLayout);
	mainLayout->addStretch();

    setLayout(mainLayout);
}

void PCAPage::changeImage(int _i){
    image = _i;
    emit done();
}

void PCAPage::changeLambda(int _i){
    lambda = _i;
    emit done();
}

int PCAPage::getImage(){
    return image;
}

int PCAPage::getType(){
    return type;
}

int PCAPage::getLambda(){
    return lambda;
}

void PCAPage::changeTypeX(bool _b){
    if(_b){
        type = 0;
        if(multipleImages) {
            lambdaComboBox->hide();
            lambdaLabel->hide();
        }
        emit done();
    }
}

void PCAPage::changeTypeY(bool _b){
    if(_b){
        type = 1;
        if(multipleImages) {
            lambdaComboBox->hide();
            lambdaLabel->hide();
        }
        emit done();
    }
}

void PCAPage::changeTypeReconstructed(bool _b){
    if(_b){
        type = 2;
        lambdaComboBox->show();
        lambdaLabel->show();
        emit done();
    }
}

void PCAPage::changeTypeDifferenceReconstructed(bool _b){
    if(_b){
        type = 3;
        lambdaComboBox->show();
        lambdaLabel->show();
        emit done();
    }
}

void PCAPage::changeTypeDifferenceY(bool _b){
    if(_b){
        type = 4;
        lambdaComboBox->hide();
        lambdaLabel->hide();
        emit done();
    }
}
